package com.ruoyi.project.qyxy.qua.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.qyxy.qua.domain.QuaInfo;
import com.ruoyi.project.qyxy.qua.service.IQuaInfoService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 企业资质Controller
 * 
 * @author lcl
 * @date 2021-03-05
 */
@RestController
@RequestMapping("/qyxy/qua")
public class QuaInfoController extends BaseController
{
    @Autowired
    private IQuaInfoService quaInfoService;

    /**
     * 查询企业资质列表
     */
    @PreAuthorize("@ss.hasPermi('qyxy:qua:list')")
    @GetMapping("/list")
    public TableDataInfo list(QuaInfo quaInfo)
    {
        startPage();
        List<QuaInfo> list = quaInfoService.selectQuaInfoList(quaInfo);
        return getDataTable(list);
    }

    /**
     * 导出企业资质列表
     */
    @PreAuthorize("@ss.hasPermi('qyxy:qua:export')")
    @Log(title = "企业资质", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QuaInfo quaInfo)
    {
        List<QuaInfo> list = quaInfoService.selectQuaInfoList(quaInfo);
        ExcelUtil<QuaInfo> util = new ExcelUtil<QuaInfo>(QuaInfo.class);
        return util.exportExcel(list, "qua");
    }

    /**
     * 获取企业资质详细信息
     */
    @PreAuthorize("@ss.hasPermi('qyxy:qua:query')")
    @GetMapping(value = "/{orgCode}")
    public AjaxResult getInfo(@PathVariable("orgCode") String orgCode)
    {
        return AjaxResult.success(quaInfoService.selectQuaInfoById(orgCode));
    }

    /**
     * 新增企业资质
     */
    @PreAuthorize("@ss.hasPermi('qyxy:qua:add')")
    @Log(title = "企业资质", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QuaInfo quaInfo)
    {
        return toAjax(quaInfoService.insertQuaInfo(quaInfo));
    }

    /**
     * 修改企业资质
     */
    @PreAuthorize("@ss.hasPermi('qyxy:qua:edit')")
    @Log(title = "企业资质", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QuaInfo quaInfo)
    {
        return toAjax(quaInfoService.updateQuaInfo(quaInfo));
    }

    /**
     * 删除企业资质
     */
    @PreAuthorize("@ss.hasPermi('qyxy:qua:remove')")
    @Log(title = "企业资质", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orgCodes}")
    public AjaxResult remove(@PathVariable String[] orgCodes)
    {
        return toAjax(quaInfoService.deleteQuaInfoByIds(orgCodes));
    }
}
